package cn.tedu.backend.portal.controller;

import cn.tedu.backend.portal.model.Season;
import cn.tedu.backend.portal.service.ISeasonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@Slf4j
public class SeasonController {
    @Resource
    private ISeasonService service;

    //查询所有
  @RequestMapping("/selectSeasons")
  public List<Season> selectSeasons(){
    return service.selectSeasons();
  }
  //根据季节名查询
  @RequestMapping("/searchSeason")
  public Season searchSeason(String season){
    return service.searchSeason(season);
  }
  //删除
  @RequestMapping("/delSeason")
  public int delSeason(String season){
    return service.delSeason(season);
  }
  //添加
  @ResponseBody
  @RequestMapping(value = "/addSeason",method = RequestMethod.POST)
  public String addSeason(@Valid Season season){
    service.addSeason(season);
   return "添加成功";
  }
  //修改
  @RequestMapping(value = "/updateSeason",method = RequestMethod.POST)
  public String updateSeason(Season season){
    service.updateSeason(season);
    return "修改成功";
  }

  //    @RequestMapping("/eventlist")
//    public PageInfo<Season> list(Integer pageNum){
//        //分页
//        if (pageNum==null)
//            pageNum=1;
//        Integer pageSize=12;
//        //添加翻页page参数   ↓↓↓↓↓↓↓↓
//        PageInfo<Season> pageInfo = service.getEvents(pageNum,pageSize);
//
//        return pageInfo;
//
//    }
//
//    @RequestMapping("/deleteEventById")
//    public int deleteById(int id){
//        return service.deleteById(id);
//    }
//
//    @RequestMapping("/userEventsById")
////    public PageInfo<Event> userEventsById(String userId,Integer pageNum){
//    public PageInfo<Season> userEventsById(Integer pageNum){
//        //分页
//        if (pageNum==null)
//            pageNum=1;
//        Integer pageSize=10;
//        //添加翻页page参数   ↓↓↓↓↓↓↓↓
////        PageInfo<Event> pageInfo = service.getuserEventsById(userId,pageNum,pageSize);
//        PageInfo<Season> pageInfo = service.getuserEventsById(pageNum,pageSize);
//        return pageInfo;
//    }
//
//    @RequestMapping("/sendEventsById")
////    public PageInfo<Event> userEventsById(String userId,Integer pageNum){
//    public PageInfo<Season> sendEventsById(Integer pageNum){
//        //分页
//        if (pageNum==null)
//            pageNum=1;
//        Integer pageSize=15;
//        //添加翻页page参数   ↓↓↓↓↓↓↓↓
////        PageInfo<Event> pageInfo = service.getsendEventsById(userId,pageNum,pageSize);
//        PageInfo<Season> pageInfo = service.getsendEventsById(pageNum,pageSize);
//        return pageInfo;
//    }
}
